#include <QGraphicsObject>
#include <QPointF>
#include <iostream>
#include <cmath>


class Car : public QGraphicsObject {
    Q_OBJECT
public:
    Car(qreal width, qreal height, QGraphicsItem* parent = nullptr);
    
    // 图形项必须实现的接口
    QRectF boundingRect() const override;
    void paint(QPainter* painter, 
              const QStyleOptionGraphicsItem* option,
              QWidget* widget) override;

    // 控制接口
    void updatePosition();
    void setSteering(qreal angle);
    void setSpeed(qreal speed);
    QPointF velocity() const;

    qreal speed() const { return m_speed; }

signals:
    void speedChanged(qreal newSpeed);

private:
    qreal m_width;
    qreal m_height;
    qreal m_speed = 0;
    qreal m_steeringAngle = 0;
    QPointF m_velocity;
    double x, y;      // 小车的位置
    double angle;     // 小车的旋转角度
};